fix UI/UX: Mode switch performance from 1 sec -> instant #2997
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Switch mode performance is very bad now (1 sec per change tag) which leads to poor UX. This PR makes it instant.
I looked but can not find any reason to keep it depending on full state update since the data is already loaded for presentation. I may be missing a reason for this architectural choice so please check.
There is also an issue I noticed Settings has a Save button but "Prompts" does not, can we standardize this? I prefer save button for clarity, autosave is OK too but would need user feedback. Either way we should standardize saving behavior across all tabs.
The other thing is, are we sending full convo history because we intend to actually change the mode in conversation or is that a bug? I neither believe users have this expectation nor do they really want that to happen. It's much better for users to have good UX on the modes page than trade-off bad UX for mode change for feature which user probably do not want. But I'm making a lot of assumptions here and maybe switching Mode here was never intended to influence the chat conversation... In that case we could turn off all backend updates until the user presses the save button which would be optimal from a cursory glance.
Screenshot
Details
For this PR:
The issue occurs because the UI waits for a complete round-trip:
Solution
Implemented an "optimistic UI update" pattern that makes mode switching feel instant:
visualModestate that's initialized with the globalmodestatevisualModeinstead ofmodevisualModeimmediately when a mode is clickedThis approach provides instant feedback to the user while maintaining proper state synchronization with the backend. The key insight is that we don't need to wait for the backend to update the UI - we can update it immediately and let the backend catch up in the background.
Implementation Details
The changes are minimal and focused on the frontend only:
visualModestate inPromptsView.tsxvisualModeinstead ofmodehandleModeSwitchfunction to updatevisualModeimmediatelyTesting
Impact
This change significantly improves the user experience when switching modes in the PromptsView component. What previously took 1-2 seconds now happens instantly, making the interface go from annoying to usable.
The changes are isolated to the frontend and don't modify any backend code, making this a lower-risk improvement.
Important
Optimizes mode switching in
PromptsView.tsxby implementing an optimistic UI update pattern using a localvisualModestate.PromptsView.tsxusing a new local statevisualMode.visualModeimmediately on mode click, providing instant feedback.handleModeSwitchto updatevisualModeimmediately.visualModeinstead ofmode.This description was created by
for d57e64e. You can customize this summary. It will automatically update as commits are pushed.